﻿//
// eCRAM, a monthly activity report web application
// Copyright (C) 2010  Aptea
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//

using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;

namespace eCRAM.Model
{
    /// <summary>
    /// A CRAM can contain several lines. Each line matches an activity.
    /// </summary>
    /// 
    /// <remarks>
    /// <code>
    /// | Activity  |  Monday   |  Tuesday  | ...
    /// |-----------|-----------|-----------|
    /// | Project A |     0     |    1/2    | > this is a line
    /// |-----------|-----------|-----------|
    /// | Project B |     1     |    1/2    | > this is a line
    /// |-----------|-----------|-----------|
    /// |  Absence  |     0     |     0     | > this is a line
    /// |-----------|-----------|-----------|
    /// </code>
    /// </remarks>
    [Table(Name = "CramLines")]
    public class CramLine
    {
        /// <summary>
        /// Do not use this constructor! Used by LINQ to SQL.
        /// Cannot be internal :/
        /// </summary>
        public CramLine()
        {
        }

        /// <summary>
        /// Creates a new CRAM line given a cram.
        /// </summary>
        /// <remarks>
        /// Don't forget to do a DataContext.SubmitChanges() on Cram before to create CramLine,
        /// otherwise Cram.Id won't have a proper value.
        /// </remarks>
        /// <param name="cram"></param>
        public CramLine(Cram cram, Activity activity, string workingdays)
        {
            CramId = cram.Id;
            ActivityId = activity.Id;
            _activity.Entity = activity;
            WorkingDays = workingdays;
            
        }

        [Column(IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)]
        public Guid Id { get; set; }

        [Column]
        internal Guid CramId { get; set; }

        [Column]
        public Guid ActivityId { get; set; }

        [Column]
        public string WorkingDays { get; set; }

        [Column]
        public string Description { get; set; }

        private EntityRef<Activity> _activity;

        [Association(Storage = "_activity", ThisKey = "ActivityId")]
        public Activity Activity { get { return _activity.Entity; } set { _activity.Entity = value; } }
    }
}
